app.controller('ManyParamssetCtrl',function ($scope,$http,$localStorage,$location,$window,$state) {
	$scope.namedata = $localStorage.cur_user.uname;	
	$scope.mmData = $localStorage.layers_info;
  // $scope.c={};
  $scope.save = function(){
  // $scope.c = $scope.b;  
  var school_id,building_type,campus_building_id,building_name,layer_id,layer_name;
    if($scope.b!=null){
      if($scope.b.school_name!=undefined&&$scope.b.school_name!=null&&$scope.b.school_name!=''){        
        if($scope.b.school_name!="所有学校"){     
          if($scope.b.buildingtype!=null&&$scope.b.buildingtype!=undefined&&$scope.b.buildingtype!=""){
            if($scope.b.building_name!=null&&$scope.b.building_name!=undefined&&$scope.b.building_name!=""){
              if($scope.b.layer_name!=null&&$scope.b.layer_name!=undefined&&$scope.b.layer_name!=""){
                school_id = $scope.mmData[$scope.b.school_name].school_id;
                building_type = $scope.b.buildingtype.split('+')[0];
                campus_building_id = $scope.b.layer_name.split('+')[1];
                building_name = $scope.b.building_name;
                layer_name = $scope.b.layer_name.split('+')[0];
                layer_id = $scope.b.layer_name.split('+')[2];           
              }else{
                school_id = $scope.mmData[$scope.b.school_name].school_id;
                building_type = $scope.b.buildingtype.split('+')[0];
                campus_building_id = $scope.mmData[$scope.b.school_name][$scope.b.buildingtype.split('+')[0]][$scope.b.building_name].campus_id;
                building_name = $scope.b.building_name;
                $scope.b.layer_name = "";
                layer_name = "所有层";
              }


            }else{

              school_id = $scope.mmData[$scope.b.school_name].school_id;
              building_type = $scope.b.buildingtype.split('+')[0];
              $scope.b.building_name = "";
              building_name = "所有楼";
            }

          }else{
            $scope.b.building_type = "";
            building_type = "所有类型";
            school_id = $scope.mmData[$scope.b.school_name].school_id;
          }
          
          
        }else{
          school_id = "";
          building_type = "";
          campus_building_id = "";
          building_name = "";
          layer_id = "" ;
          layer_name = "" ;
        }
      }else{
        alert("请选择学校")
      }
    }else{
      alert("请选择学校")
    }  

      $http.post(
        $scope.app.backendurl+"tbl-electricity-manage/set-many-params",
        {    
          'school_id':school_id, 
          'school_name':$scope.b.school_name,
          'campus_building_id':campus_building_id,
          'building_name':building_name,
          'building_type':building_type,
          'layer_id':layer_id,
          'layer_name':layer_name,
          'max_power':$scope.b.max_power,
          'auto_regain_min':$scope.b.auto_regain_min,     
          'token':$localStorage.token                  

        }
        ).success(function (data) {
            //console.log(data);
            if(data.code==0&&data.msg=="成功设定设备参数"){             
              alert(data.msg);
              $state.go('app.control.electricquantity')               
            }
            if(data.code==1){             
              alert(data.msg)
                    
            }
            if(data.code==20001&&data.msg=='请先登录'){
              $location.path('access.signin');
            }  
        
       
        }).error(function(data){
          alert(data.msg);
        })

    }
  

	


	

})